home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / m2gem106.lzh / CRYSTAL1.06 / TST / XSAMPLE / XSAMPLE.M2
Encoding:
Text File  |  1994-01-15  |  17.4 KB  |  625 lines

  1. (***************************************************************************)
  2. (* GEM sample application                                                  *)
  3. (* adapted from apskel.c by Ron Zdybl, Atari Corp.                         *)
  4. (*                                                                         *)
  5. (* UK 01/15/1994                                                           *)
  6. (***************************************************************************)
  7.  
  8. MODULE XSample;
  9.  
  10. FROM AES        IMPORT Root,Nil,ObjectIndex,ObjectPtr,TreeIndex,
  11.                        TreePtr,StringPtr,
  12.                        ObjectState,Selected,State15,Checked,
  13.                        HideTree,Key,SpecialKey,KLShift,KRShift,
  14.                        MouseButton,MBLeft;
  15. FROM ApplMgr    IMPORT ApplInit,ApplExit,ApplWrite;
  16. FROM EvntMgr    IMPORT EvntEvent,MEvent,MuMesag,MuKeybd,MuButton,Event,
  17.                        MessageBlock,ApMsg,ApTerm,ApDragDrop,
  18.                        WMRedraw,WMNewTop,WMTopped,WMSized,WMMoved,WMFulled,
  19.                        WMClosed,MnSelected;
  20. FROM ObjcMgr    IMPORT ObjcDraw,MaxDepth,ObjcOffset,ObjcFind,ObjcChange;
  21. FROM FormMgr    IMPORT FmDStart,FmDGrow,FmDShrink,FmDFinish,FormDial,
  22.                        FormCenter,FormDo;
  23. FROM MenuMgr    IMPORT MenuICheck,MenuText,MenuTNormal;
  24. FROM GrafMgr    IMPORT GrafHandle,GrafMKState,GrafGrowBox,GrafShrinkBox;
  25. FROM RsrcMgr    IMPORT RsrcLoad,RsrcFree;
  26. FROM WindMgr    IMPORT NoWindow,Desk,WindCreate,WindOpen,WindClose,
  27.                        WindFind,WindDelete,WindCalc,WCBorder,WCWork,
  28.                        Wind,Name,Close,Full,Move,Info,Size,HSlide,VSlide;
  29. FROM RcMgr      IMPORT GRect,GPnt,RcSnap,RcIntersect,RcEqual;
  30. FROM MenuTool   IMPORT ShowMenu,HideMenu,MenuKey,NewMenuAction,MenuAction;
  31. FROM ObjcTool   IMPORT ObjectXYWH,INCLObjectState,EXCLObjectState,
  32.                        INCLObjectFlags,EXCLObjectFlags,TreeWalk,
  33.                        NewObjectCallback,ObjectCall,Indirect;
  34. FROM FormTool   IMPORT OK,Alert,Mask;
  35. FROM RsrcTool   IMPORT GetTreePtr,GetFreeStringPtr;
  36. FROM GrafTool   IMPORT ShowMouse,HideMouse,BusyMouse,MouseForm,FlatHand,
  37.                        PointingHand,ArrowMouse,LastMouse,
  38.                        RubberBox,HotDragBox;
  39. FROM WindTool   IMPORT GetWorkXYWH,GetFirstXYWH,GetNextXYWH,SetTop,
  40.                        SetName,SetInfo,SetCurrXYWH,GetCurrXYWH,
  41.                        GetFullXYWH,GetPrevXYWH,
  42.                        BeginUpdate,EndUpdate,
  43.                        BeginMouseControl,EndMouseControl,
  44.                        RedrawWindow;
  45. FROM DeskTool   IMPORT OpenDesk,CloseDesk,DrawDeskObject;
  46. FROM VDI        IMPORT XY,White,Black,Blue;
  47. FROM VAttribute IMPORT VSFInterior,FISPattern,VSFStyle,VSFColor;
  48. FROM VOutput    IMPORT VBar,VEllipse;
  49. FROM VDITool    IMPORT OpenVirtualWorkstation,CloseVirtualWorkstation,
  50.                        SetClip,GRectToArray;
  51. FROM INTRINSIC  IMPORT VOID,PTR;
  52. FROM PORTAB     IMPORT UNSIGNEDWORD,SIGNEDWORD;
  53.  
  54. IMPORT FlyingLook,SetObject,GetObject;
  55.  
  56. (* Resource Indices *)
  57.  
  58. CONST
  59.  
  60.     MENU     =   0;    (* Menuebaum *)
  61.     TINFO    =   3;    (* TITLE in Baum MENU *)
  62.     TFILE    =   4;    (* TITLE in Baum MENU *)
  63.     TEDIT    =   5;    (* TITLE in Baum MENU *)
  64.     TOPTION  =   6;    (* TITLE in Baum MENU *)
  65.     IINFO    =   9;    (* STRING in Baum MENU *)
  66.     INEW     =  18;    (* STRING in Baum MENU *)
  67.     IOPEN    =  19;    (* STRING in Baum MENU *)
  68.     ISAVE    =  21;    (* STRING in Baum MENU *)
  69.     IQUIT    =  28;    (* STRING in Baum MENU *)
  70.     IUNDO    =  30;    (* STRING in Baum MENU *)
  71.     ICUT     =  32;    (* STRING in Baum MENU *)
  72.     ICOPY    =  33;    (* STRING in Baum MENU *)
  73.     IPASTE   =  34;    (* STRING in Baum MENU *)
  74.     IDELETE  =  36;    (* STRING in Baum MENU *)
  75.     IWARNING =  38;    (* STRING in Baum MENU *)
  76.     IHELP    =  39;    (* STRING in Baum MENU *)
  77.     IELL     =  41;    (* STRING in Baum MENU *)
  78.     IRS232   =  42;    (* STRING in Baum MENU *)
  79.     IFORMAT  =  43;    (* STRING in Baum MENU *)
  80.  
  81.     DESK     =   1;    (* Formular/Dialog *)
  82.     DISKA    =   3;    (* ICON in Baum DESK *)
  83.     DISKB    =   4;    (* ICON in Baum DESK *)
  84.     FOLDER   =   5;    (* ICON in Baum DESK *)
  85.     COLICON  =   6;    (* ICON in Baum DESK *)
  86.  
  87.     INFO     =   2;    (* Formular/Dialog *)
  88.     INFOK    =   1;    (* BUTTON in Baum INFO *)
  89.     INFTITLE =   4;    (* STRING in Baum INFO *)
  90.  
  91.     SCANCODE =   3;    (* Formular/Dialog *)
  92.  
  93.     RADIOBUT =   4;    (* Formular/Dialog *)
  94.  
  95.     FLYINGAL =   5;    (* Formular/Dialog *)
  96.     ALRTIMG0 =   1;    (* IMAGE in Baum FLYINGAL *)
  97.  
  98.     RS232    =   6;    (* Formular/Dialog *)
  99.     RSOK     =   1;    (* BUTTON in Baum RS232 *)
  100.     RSCANCEL =   2;    (* BUTTON in Baum RS232 *)
  101.     RSTITLE  =  24;    (* STRING in Baum RS232 *)
  102.  
  103.     ELLEDIT  =   7;    (* Formular/Dialog *)
  104.     ELLCANCL =   3;    (* BUTTON in Baum ELLEDIT *)
  105.     ELLOK    =   4;    (* BUTTON in Baum ELLEDIT *)
  106.  
  107.     PGFORMAT =   8;    (* Formular/Dialog *)
  108.     PGOK     =   2;    (* BUTTON in Baum PGFORMAT *)
  109.     PGCANCEL =   3;    (* BUTTON in Baum PGFORMAT *)
  110.  
  111.     FORMAT   =   9;    (* Formular/Dialog *)
  112.  
  113.     MSRUNIT  =  10;    (* Formular/Dialog *)
  114.  
  115.     OUTPUTTO =  11;    (* Formular/Dialog *)
  116.  
  117.     WNAME    =   0;    (* Freier String *)
  118.  
  119.     WINFO    =   1;    (* Freier String *)
  120.  
  121.     HELPON   =   2;    (* Freier String *)
  122.  
  123.     HELPOFF  =   3;    (* Freier String *)
  124.  
  125.     NOWIND   =   4;    (* Alert String *)
  126.  
  127.     NOVWORK  =   5;    (* Alert String *)
  128.  
  129.     QUIT     =   6;    (* Alert String *)
  130.  
  131.     DOUBLECL =   7;    (* Alert String *)
  132.  
  133.     DRAGDROP =   8;    (* Alert String *)
  134.  
  135.     CANCELSL =   9;    (* Alert String *)
  136.  
  137. CONST RscName   = "XSAMPLE.RSC";
  138.       MyFeature = Wind{Name,Close,Full,Move,Info,Size,HSlide,VSlide};
  139.  
  140. VAR ApplId    : SIGNEDWORD;
  141.     VirtScreen: UNSIGNEDWORD;
  142.  
  143.     MyMenu    : TreePtr;
  144.     MyDesk    : TreePtr;
  145.     MyName    : StringPtr;
  146.     MyInfo    : StringPtr;
  147.     HelpItem  : StringPtr;
  148.  
  149.     MyWindow  : SIGNEDWORD;
  150.  
  151.     Work      : GRect;
  152.     XEll      : UNSIGNEDWORD;
  153.     YEll      : UNSIGNEDWORD;
  154.     WEll      : UNSIGNEDWORD;
  155.     HEll      : UNSIGNEDWORD;
  156.  
  157.     CharWidth : UNSIGNEDWORD;
  158.     CharHeight: UNSIGNEDWORD;
  159.     BoxWidth  : UNSIGNEDWORD;
  160.     BoxHeight : UNSIGNEDWORD;
  161.  
  162.     MinWidth  : SIGNEDWORD;
  163.     MinHeight : SIGNEDWORD;
  164.  
  165. PROCEDURE OpenWindow(VAR Window: SIGNEDWORD): BOOLEAN;
  166.  
  167. VAR Start: GRect;
  168.     Full : GRect;
  169.  
  170. BEGIN
  171.   GetWorkXYWH(Desk,Full);
  172.   Window:= WindCreate(MyFeature,Full);
  173.   IF Window # NoWindow THEN
  174.  
  175.     MyName:= GetFreeStringPtr(WNAME);
  176.     SetName(Window,MyName^);
  177.  
  178.     MyInfo:= GetFreeStringPtr(WINFO);
  179.     SetInfo(Window,MyInfo^);
  180.  
  181.     WITH Full DO
  182.       Start.GX:= GX + GW DIV 2;
  183.       Start.GY:= GY + GH DIV 2;
  184.       Start.GW:= BoxWidth;
  185.       Start.GH:= BoxHeight;
  186.     END;
  187.  
  188.     GrafGrowBox(Start,Full);
  189.     WindOpen(Window,Full);
  190.   END;
  191.   RETURN Window # NoWindow;
  192. END OpenWindow;
  193.  
  194. PROCEDURE CloseWindow(Window: SIGNEDWORD);
  195.  
  196. VAR Start: GRect;
  197.     End  : GRect;
  198.     Full : GRect;
  199.  
  200. BEGIN
  201.   GetCurrXYWH(Window,Start);
  202.   GetWorkXYWH(Desk,Full);
  203.  
  204.   WITH Full DO
  205.     End.GX:= GW DIV 2;
  206.     End.GY:= GH DIV 2;
  207.     End.GW:= BoxWidth;
  208.     End.GH:= BoxHeight;
  209.   END;
  210.  
  211.   WindClose(Window);
  212.   GrafShrinkBox(End,Start);
  213.   WindDelete(Window);
  214. END CloseWindow;
  215.  
  216. PROCEDURE DrawSample(VAR Rect: GRect);
  217.  
  218. VAR Points: ARRAY[0..3] OF XY;
  219.     Work  : GRect;
  220.  
  221. BEGIN
  222.   SetClip(VirtScreen,Rect);
  223.   VSFInterior(VirtScreen,FISPattern);
  224.   VSFStyle(VirtScreen,8);
  225.   VSFColor(VirtScreen,White);
  226.   GetWorkXYWH(MyWindow,Work);
  227.   GRectToArray(Work,Points);
  228.   VBar(VirtScreen,Points);
  229.  
  230.   XEll:= Work.GX;
  231.   YEll:= Work.GY;
  232.   VSFInterior(VirtScreen,FISPattern);
  233.   VSFStyle(VirtScreen,8);
  234.   VSFColor(VirtScreen,Blue);
  235.   VEllipse(VirtScreen,XEll + WEll DIV 2,
  236.                       YEll + HEll DIV 2,
  237.                       WEll DIV 2,
  238.                       HEll DIV 2);
  239. END DrawSample;
  240.  
  241. PROCEDURE DoRedraw(    Window: SIGNEDWORD;
  242.                    VAR Clip  : GRect);
  243. BEGIN
  244.   RedrawWindow(Window,Clip,DrawSample);
  245. END DoRedraw;
  246.  
  247. PROCEDURE DoSize(Window: SIGNEDWORD; VAR Rect: GRect);
  248. BEGIN
  249.   WITH Rect DO
  250.     IF GW < MinWidth THEN
  251.       GW:= MinWidth;
  252.     END;
  253.     IF GH < MinHeight THEN
  254.       GH:= MinHeight;
  255.     END;
  256.   END;
  257.   SetCurrXYWH(Window,Rect);
  258. END DoSize;
  259.  
  260. PROCEDURE DoFull(Window: SIGNEDWORD);
  261.  
  262. VAR Prev: GRect;
  263.     Curr: GRect;
  264.     Full: GRect;
  265.  
  266. BEGIN
  267.   GetFullXYWH(Window,Full);
  268.   GetCurrXYWH(Window,Curr);
  269.   GetPrevXYWH(Window,Prev);
  270.   IF RcEqual(Curr,Full) THEN
  271.     GrafShrinkBox(Prev,Full);
  272.     SetCurrXYWH(Window,Prev);
  273.   ELSE
  274.     GrafGrowBox(Curr,Full);
  275.     SetCurrXYWH(Window,Full);
  276.   END;
  277. END DoFull;
  278.  
  279. PROCEDURE DoClose(Window: SIGNEDWORD);
  280.  
  281. VAR MyMessage: MessageBlock;
  282.  
  283. BEGIN
  284.   WITH MyMessage DO
  285.     Type  := MnSelected;
  286.     Id    := ApplId;
  287.     Length:= 0;
  288.     Title := TFILE;
  289.     Item  := IQUIT;
  290.   END;
  291.   ApplWrite(ApplId,16,MyMessage);
  292. END DoClose;
  293.  
  294. PROCEDURE DoForm(Menu  : TreePtr;
  295.                  Title : ObjectIndex;
  296.                  TreeNo: TreeIndex;
  297.                  Start : ObjectIndex): ObjectIndex;
  298.  
  299. VAR Tree  : TreePtr;
  300.     From  : GRect;
  301.     To    : GRect;
  302.     Return: SIGNEDWORD;
  303.  
  304. BEGIN
  305.   ObjectXYWH(Menu,Title,From);
  306.   Tree:= GetTreePtr(TreeNo);
  307.   FormCenter(Tree,To);
  308.   BeginUpdate;
  309.   FormDial(FmDStart,To,To);
  310.   FormDial(FmDGrow,From,To);
  311.   ObjcDraw(Tree,Root,MaxDepth,To);
  312.   Return:= Mask(FormDo(Tree,Start));
  313.  
  314.   (* using FlyingLook you have to call FormCenter() a second time! *)
  315.  
  316.   FormCenter(Tree,To);
  317.  
  318.   ObjcChange(Tree,Return,1,To,
  319.              GetObject.State(Tree,Return) - ObjectState{Selected},FALSE);
  320.   FormDial(FmDShrink,From,To);
  321.   FormDial(FmDFinish,To,To);
  322.   EndUpdate;
  323.   RETURN Return;
  324. END DoForm;
  325.  
  326. PROCEDURE DoInfo(Menu: TreePtr; Title: ObjectIndex);
  327. BEGIN
  328.   VOID(DoForm(Menu,Title,INFO,0));
  329. END DoInfo;
  330.  
  331. PROCEDURE DoEllipse(Menu: TreePtr; Title: ObjectIndex);
  332. BEGIN
  333.   VOID(DoForm(Menu,Title,ELLEDIT,0));
  334. END DoEllipse;
  335.  
  336. PROCEDURE DoRSCancel(Tree: TreePtr; Index: ObjectIndex);
  337. BEGIN
  338.   Alert(CANCELSL);
  339. END DoRSCancel;
  340.  
  341. PROCEDURE DoRS232(Menu: TreePtr; Title: ObjectIndex);
  342.  
  343. VAR Ret: ObjectIndex;
  344.  
  345. BEGIN
  346.   Ret:= DoForm(Menu,Title,RS232,0);
  347.   IF Indirect(GetTreePtr(RS232),Ret) THEN
  348.     ObjectCall(GetTreePtr(RS232),Ret);
  349.   END;
  350. END DoRS232;
  351.  
  352. PROCEDURE DoFormat(Menu: TreePtr; Title: ObjectIndex);
  353. BEGIN
  354.   VOID(DoForm(Menu,Title,PGFORMAT,0));
  355. END DoFormat;
  356.  
  357. PROCEDURE ToggleHelp(Menu: TreePtr; Title: ObjectIndex);
  358. BEGIN
  359.   IF State15 IN GetObject.State(Menu,IHELP) THEN
  360.     HelpItem:= GetFreeStringPtr(HELPOFF);
  361.     EXCLObjectState(Menu,IHELP,State15);
  362.   ELSE
  363.     HelpItem:= GetFreeStringPtr(HELPON);
  364.     INCLObjectState(Menu,IHELP,State15);
  365.   END;
  366.   MenuText(Menu,IHELP,HelpItem^);
  367. END ToggleHelp;
  368.  
  369. PROCEDURE ToggleWarning(Menu: TreePtr; Title: ObjectIndex);
  370. BEGIN
  371.   MenuICheck(Menu,IWARNING,NOT(Checked IN GetObject.State(Menu,IWARNING)));
  372. END ToggleWarning;
  373.  
  374. PROCEDURE DoNothing(Menu: TreePtr; Title: ObjectIndex);
  375. BEGIN
  376. END DoNothing;
  377.  
  378. PROCEDURE DoMenu(Title: ObjectIndex; Item: ObjectIndex);
  379. BEGIN
  380.   ArrowMouse;
  381.   MenuAction(MyMenu,Title,Item);
  382.   MenuTNormal(MyMenu,Title,TRUE);
  383. END DoMenu;
  384.  
  385. PROCEDURE DeselectAll(Tree: TreePtr; Index: ObjectIndex): BOOLEAN;
  386. BEGIN
  387.   IF Selected IN GetObject.State(Tree,Index) THEN
  388.     EXCLObjectState(Tree,Index,Selected);
  389.     DrawDeskObject(Tree,Index);
  390.   END;
  391.   RETURN TRUE;
  392. END DeselectAll;
  393.  
  394. PROCEDURE DoClick(Clicks: UNSIGNEDWORD; Pos: GPnt);
  395.  
  396. VAR MyIcon        : ObjectPtr;
  397.     Index         : ObjectIndex;
  398.     Dummy         : GPnt;
  399.     Special       : SpecialKey;
  400.     PressedButtons: MouseButton;
  401.     Box           : GRect;
  402.     Rect          : GRect;
  403.  
  404.   PROCEDURE MoveObject(Pos: GPnt; Tree: TreePtr; Ob: ObjectIndex);
  405.  
  406.   VAR DeskRect: GRect;
  407.       Box     : GRect;
  408.       OldPos  : GPnt;
  409.       NewPos  : GPnt;
  410.  
  411.   BEGIN
  412.     ObjcOffset(Tree,Ob,OldPos.GX,OldPos.GY);
  413.     ObjectXYWH(Tree,Root,DeskRect);
  414.  
  415.     BeginUpdate;
  416.     BeginMouseControl;
  417.  
  418.     MouseForm(FlatHand);
  419.  
  420.     NewPos:= Pos;
  421.     ObjectXYWH(Tree,Ob,Box);
  422.     VOID(HotDragBox(NewPos,Box,DeskRect,Tree));
  423.  
  424.     LastMouse;
  425.  
  426.     EndMouseControl;
  427.     EndUpdate;
  428.  
  429.     IF WindFind(NewPos) = Desk THEN
  430.       INCLObjectFlags(Tree,Ob,HideTree);
  431.       DrawDeskObject(Tree,Ob);
  432.       SetObject.X(Tree,Ob,RcSnap(GetObject.X(Tree,Ob) + NewPos.GX - OldPos.GX,80));
  433.       SetObject.Y(Tree,Ob,RcSnap(GetObject.Y(Tree,Ob) + NewPos.GY - OldPos.GY,48));
  434.       EXCLObjectFlags(Tree,Ob,HideTree);
  435.       DrawDeskObject(Tree,Ob);
  436.     END;
  437.   END MoveObject;
  438.  
  439. BEGIN
  440.   BeginUpdate;
  441.   BeginMouseControl;
  442.   IF WindFind(Pos) = Desk THEN
  443.     MyIcon:= ObjcFind(MyDesk,Root,1,Pos);
  444.  
  445.     IF Clicks = 2 THEN
  446.       IF MyIcon >= DISKA THEN
  447.         INCLObjectState(MyDesk,MyIcon,Selected);
  448.         DrawDeskObject(MyDesk,MyIcon);
  449.         Alert(DOUBLECL);
  450.         EXCLObjectState(MyDesk,MyIcon,Selected);
  451.         DrawDeskObject(MyDesk,MyIcon);
  452.       END;
  453.     ELSIF Clicks = 1 THEN
  454.       GrafMKState(Dummy,PressedButtons,Special); (* button still pressed? *)
  455.  
  456.       IF MBLeft IN PressedButtons THEN (* left button pressed *)
  457.         TreeWalk(MyDesk,DISKA,Nil,DeselectAll);
  458.         IF MyIcon >= DISKA THEN (* pressed on an icon *)
  459.           INCLObjectState(MyDesk,MyIcon,Selected);
  460.           DrawDeskObject(MyDesk,MyIcon);
  461.           MoveObject(Pos,MyDesk,MyIcon);
  462.         ELSE                    (* pressed on the desk *)
  463.           RubberBox(Pos,Box);
  464.           FOR Index:= DISKA TO COLICON DO
  465.             ObjectXYWH(MyDesk,Index,Rect);
  466.             IF RcIntersect(Box,Rect) THEN
  467.               INCLObjectState(MyDesk,Index,Selected);
  468.               DrawDeskObject(MyDesk,Index);
  469.             END;
  470.           END;
  471.         END;
  472.       ELSE (* single click, but button no more pressed *)
  473.         IF MyIcon >= DISKA THEN (* single click on an icon *)
  474.           IF (SpecialKey{KLShift,KRShift} * Special # SpecialKey{}) THEN
  475.             SetObject.State(MyDesk,
  476.                             MyIcon,
  477.                             GetObject.State(MyDesk,MyIcon) / ObjectState{Selected});
  478.             DrawDeskObject(MyDesk,MyIcon);
  479.           ELSE (* without shift *)
  480.             IF NOT(Selected IN GetObject.State(MyDesk,MyIcon)) THEN
  481.               TreeWalk(MyDesk,DISKA,Nil,DeselectAll);
  482.               INCLObjectState(MyDesk,MyIcon,Selected);
  483.               DrawDeskObject(MyDesk,MyIcon);
  484.             END;
  485.           END;
  486.         ELSE                    (* single click on the desk *)
  487.           TreeWalk(MyDesk,DISKA,Nil,DeselectAll);
  488.         END;
  489.       END;
  490.     END;
  491.   END;
  492.   EndMouseControl;
  493.   EndUpdate;
  494. END DoClick;
  495.  
  496. PROCEDURE EventLoop;
  497.  
  498. VAR EventBlock: MEvent;
  499.     MyEvent   : Event;
  500.     MyMessage : MessageBlock;
  501.     Clicks    : UNSIGNEDWORD;
  502.  
  503. BEGIN
  504.   WITH EventBlock DO
  505.     EFlags:= Event{MuMesag,MuKeybd,MuButton};
  506.     EMePBuf:= PTR(MyMessage);
  507.     EBClk:= 2;
  508.     EBMsk:= MouseButton{MBLeft};
  509.     EBSt:= MouseButton{MBLeft};
  510.  
  511.     WITH MyMessage DO
  512.       LOOP
  513.         MyEvent:= EvntEvent(EventBlock);
  514.  
  515.         IF MuMesag IN MyEvent THEN
  516.           CASE Type OF
  517.             WMRedraw:
  518.               DoRedraw(Handle,Rect);
  519.           | WMNewTop,WMTopped:
  520.               SetTop(Handle);
  521.           | WMSized:
  522.               DoSize(Handle,Rect);
  523.           | WMMoved:
  524.               SetCurrXYWH(Handle,Rect);
  525.           | WMFulled:
  526.               DoFull(Handle);
  527.           | WMClosed,ApTerm:
  528.               DoClose(Handle);
  529.           | MnSelected:
  530.               DoMenu(Title,Item);
  531.           | ApDragDrop:
  532.               Alert(DRAGDROP);
  533.           ELSE
  534.             ;
  535.           END;
  536.         END;
  537.  
  538.         IF MuButton IN MyEvent THEN
  539.           DoClick(EBR,EMXY);
  540.         END;
  541.  
  542.         IF MuKeybd IN MyEvent THEN
  543.           IF NOT MenuKey(MyMenu,EKR,EKS) THEN
  544.             (* DoKey(EKR,EKS); *)
  545.           END;
  546.         END;
  547.  
  548.         IF (Type = MnSelected) AND (Item = IQUIT) THEN
  549.           IF OK(QUIT) THEN
  550.             EXIT;
  551.           ELSE
  552.             Type:= ApMsg;
  553.           END;
  554.         END;
  555.  
  556.       END;
  557.     END;
  558.   END;
  559. END EventLoop;
  560.  
  561. BEGIN
  562.   ApplId:= ApplInit();
  563.  
  564.   IF ApplId >= 0 THEN
  565.     BeginUpdate;
  566.     BusyMouse;
  567.  
  568.     IF RsrcLoad(RscName) THEN
  569.       IF OpenVirtualWorkstation(VirtScreen) THEN
  570.         MyMenu:= GetTreePtr(MENU);
  571.  
  572.         NewMenuAction(MyMenu,IINFO,DoInfo);
  573.         NewMenuAction(MyMenu,IHELP,ToggleHelp);
  574.         NewMenuAction(MyMenu,IELL,DoEllipse);
  575.         NewMenuAction(MyMenu,IRS232,DoRS232);
  576.         NewMenuAction(MyMenu,IFORMAT,DoFormat);
  577.         NewMenuAction(MyMenu,IWARNING,ToggleWarning);
  578.         NewMenuAction(MyMenu,IQUIT,DoNothing);
  579.  
  580.         NewObjectCallback(GetTreePtr(RS232),RSCANCEL,DoRSCancel);
  581.  
  582.         ShowMenu(MyMenu);
  583.  
  584.         MyDesk:= GetTreePtr(DESK);
  585.         OpenDesk(MyDesk,Root);
  586.  
  587.         VOID(GrafHandle(CharWidth,CharHeight,BoxWidth,BoxHeight));
  588.         MinWidth:= 2 * BoxWidth;
  589.         MinHeight:= 2 * BoxHeight;
  590.  
  591.         IF OpenWindow(MyWindow) THEN
  592.           ArrowMouse;
  593.           EndUpdate;
  594.  
  595.           GetWorkXYWH(MyWindow,Work);
  596.           WITH Work DO
  597.             XEll:= GX;
  598.             YEll:= GY;
  599.             WEll:= GW;
  600.             HEll:= GH;
  601.           END;
  602.  
  603.           EventLoop;
  604.  
  605.           CloseWindow(MyWindow);
  606.         ELSE
  607.           Alert(NOWIND);
  608.         END;
  609.  
  610.         CloseDesk;
  611.         HideMenu(MyMenu);
  612.         CloseVirtualWorkstation(VirtScreen);
  613.       ELSE
  614.         Alert(NOVWORK);
  615.       END;
  616.  
  617.       RsrcFree;
  618.     ELSE
  619.       EndUpdate;
  620.     END;
  621.     ApplExit;
  622.   END;
  623. END XSample.
  624.  
  625.